// 全局加载动画状态定义
import { defineStore } from 'pinia'

export const useLoadingStore = defineStore('loading', {
  state: () => ({
    count: 0,
    isLoading: false
  }),
  actions: {
    //可能一次性发出多个请求，所以这里不单纯采用布尔，而是采用计数制
    startLoading() {
        
      this.count++
      this.isLoading = true
    },
    finishLoading() {
      this.count--
      if (this.count <= 0) {
        this.count = 0
        this.isLoading = false
      }
    }
  }
})